package com.feeyin.radar.commons;

import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class DatePropertyEditor extends PropertyEditorSupport
{
  public String getAsText()
  {
    java.sql.Date date = (java.sql.Date)getValue();
    return date.toString();
  }

  public void setAsText(String arg0) throws IllegalArgumentException
  {
    if ((arg0 != null) && (!arg0.equals(""))) {
      SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
      java.util.Date date = null;
      try {
        date = simpleDateFormat.parse(arg0);
        setValue(new java.sql.Date(date.getTime()));
      }
      catch (ParseException e) {
        e.printStackTrace();
      }
    } else {
      setValue(null);
    }
  }
}